package com.home.work.utils;

import com.home.work.constant.Resources;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class FileUtils {
    private String previousPath = "";

    public void listAllFile(){

        ClassLoader classLoader = getClass().getClassLoader();
        URL url = classLoader.getResource("");
        previousPath = url.getPath().substring(1);
        System.out.println(previousPath);
        getChildPath(previousPath);
    }

    public void getChildPath(String parentPath){
        File file = new File(parentPath);
        if(file.isDirectory()){
            File[] files = file.listFiles();
            Stream.of(files).forEach(file1 -> {
                getChildPath(file1.getAbsolutePath());
            });
        }else {
            String name = file.getName();
            if(name.endsWith(".class")){
                String absolutePath = file.getAbsolutePath().replaceAll("\\\\","/").replace(previousPath,"");
                String str = absolutePath.replaceAll("/", ".").replace(".class","");;
                Resources.classFullPath.add(str);
            }
        }
    }
}
